#!/usr/bin/env python
# encoding: utf-8
'''
poc.TTaskBarIcon -- shortdesc

poc.TTaskBarIcon is a description

It defines classes_and_methods

@author:     Anson Chan

@copyright:  2016 Xerland Co. Ltd. All rights reserved.

@contact:    anson_chan@xerland.com
@deffield    updated: Updated
'''
#!/usr/bin/python
# _*_ coding: utf-8 _*_

import wx
class TaskBarIcon(wx.TaskBarIcon):
    ID_Exit = wx.NewId()
    def __init__(self, frame):
        wx.TaskBarIcon.__init__(self)
        self.frame = frame
        self.SetIcon(wx.Icon(name='TPlus2.ico', type=wx.BITMAP_TYPE_ICO), 'TPlus')
#        self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarLeftDClick)
        self.Bind(wx.EVT_MENU, self.OnExit, id=self.ID_Exit)
#
#    def OnTaskBarLeftDClick(self, event):
#        if self.frame.IsIconized():
#           self.frame.Iconize(False)
#        if not self.frame.IsShown():
#           self.frame.Show(True)
#        self.frame.Raise()

    def OnExit(self, event):
#        wx.MessageBox('Hello From TaskBarIcon!', 'Prompt')
        self.frame.OnClose(self.frame)

    # override
    def CreatePopupMenu(self):
        menu = wx.Menu()
        menu.Append(self.ID_Exit, 'Exit')
        return menu

class Frame(wx.Frame):
    def __init__(
            self, parent=None, id=wx.ID_ANY, title='TaskBarIcon', pos=wx.DefaultPosition,
            size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
            ):
        wx.Frame.__init__(self, parent, id, title, pos, size, style) 
        self.screenIm = "TPlus3.ico" 

        # create a welcome screen
        screen = wx.Image(self.screenIm).ConvertToBitmap()
        wx.SplashScreen(screen, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,1000, None, -1)
        wx.Yield()
       
        self.SetIcon(wx.Icon('TPlus2.ico', wx.BITMAP_TYPE_ICO))
#        panel = wx.Panel(self, wx.ID_ANY)
#        button = wx.Button(panel, wx.ID_ANY, 'Hide Frame', pos=(60, 60))
       
#        sizer.Add(button, 0)
        self.taskBarIcon = TaskBarIcon(self)        
       
        # bind event
        self.Bind(wx.EVT_CLOSE, self.OnClose)
    def OnHide(self, event):
        self.Hide()
        
    def OnIconfiy(self, event):
        event.Skip()
        
    def OnClose(self, event):
        self.taskBarIcon.Destroy()
        self.Destroy()

def MainFrame():
    app = wx.App()
    frame = Frame(size=(640, 480))
    frame.Centre()
#    frame.Show()
    app.MainLoop()
if __name__ == '__main__':
    MainFrame()